<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>微信扫码结果</title>
    <!-- 导入vuejs和axios -->
    <script src="./plugins/vue/dist/vue.js"></script>
    <script src="./plugins/axios/dist/axios.js"></script>
    <script type="text/javascript" src="./js/common.js"></script>
</head>
<body>
    <div id="app">
        <h2>微信扫码成功！</h2>
    </div>
    <script type="text/javascript">
        new Vue({
            el:"#app",
            methods:{

            },
            mounted(){
                //获取到地址栏中code参数
                let code = getQueryStringByName("code");
                console.debug(code)
                //发送请求到我们后端项目中
                this.$http.get("/lr/wechatLogin/"+code).then(res => {
                    let {success, msg, data} = res.data
                    if(success && msg == "binded"){
                        //获取data中的userToken和loginUser，保存到localStorage中
                        localStorage.setItem("userToken", data.userToken)
                        localStorage.setItem("loginUser", data.loginUser)
                        //直接跳转到首页
                        location.href = '/index.html'
                    }else if(msg == "unbind"){
                        alert("请绑定本系统用户！");
                        //未绑定当前系统用户，就跳转到绑定页面
                        location.href = '/wechatUserBind.html?access_token='+data.access_token+'&openid='+data.openid
                    }else{
                        alert(msg);
                        location.href = 'http://localhost/login.html'
                    }
                })
            }
        })
    </script>
</body>
</html>